/**
 * @description:
 * @title: DeadLockDemo
 * @author: zp
 * @date: 2021/8/7 20:11
 * 死锁相关的问题
 * 关于死锁问题的排查
 *  1、使用jps -l 查询出可能出现问题的运行信息
 *  2、使用jstack 问题进程ID 查询出报错日志 查看问题情况
 *      Java stack information for the threads listed above:
 *      ===================================================
 *      "Thread-1":
 *         at LockDead.run(DeadLockDemo.java:22)
 *         - waiting to lock <0x000000076c055fb8> (a java.lang.String)
 *         - locked <0x000000076c055ff0> (a java.lang.String)
 *         at java.lang.Thread.run(Thread.java:748)
 *      "Thread-0":
 *         at LockDead.run(DeadLockDemo.java:22)
 *         - waiting to lock <0x000000076c055ff0> (a java.lang.String)
 *         - locked <0x000000076c055fb8> (a java.lang.String)
 *         at java.lang.Thread.run(Thread.java:748)
 *
 *      Found 1 deadlock.
 */
class LockDead implements Runnable{
    private String lockA;
    private String lockB;

    public LockDead(String lockA, String lockB) {
        this.lockA = lockA;
        this.lockB = lockB;
    }

    @Override
    public void run() {
        synchronized (lockA){
            System.out.println("线程A持有"+lockA);
            synchronized (lockB){
                System.out.println("线程B持有"+lockB);
            }
        }
    }
}

public class DeadLockDemo {
    public static void main(String[] args) {
        String lockA="lockA";
        String lockB="lockB";
        new Thread(new LockDead(lockA,lockB)).start();
        new Thread(new LockDead(lockB,lockA)).start();
    }
}
